<template>
  <div class="App-footer" :class="{homeg:isActive,homeaag:!isActive}" v-if="footerif">
    <div class="flec">
      <router-link to="/" exact>
        <van-icon name="wap-home-o" size="1.2rem"/>首页
      </router-link>
      <router-link to="/about">
        <van-icon name="apps-o" size="1.2rem"/>推荐
      </router-link>
      <router-link to="/piano">
        <van-icon name="chat-o" size="1.2rem" />钢琴
      </router-link>
      <router-link to="/mine">
       <van-icon name="friends-o" size="1.2rem"/>我的
      </router-link>
    </div>
  </div>
</template>

<script>
export default {
  name: "AppFooter",
  data() {
    return {
      isActive: true,
      footerif: true
    };
  },
  watch: {
    $route(route) {
      console.log(route.name);
      route.name == "Home"
        ? this.$store.commit("footerName", true)
        : this.$store.commit("footerName", false);
      this.title = route.meta.title;
      this.isActive = this.$store.state.footerDate;
      route.name == "Rank" || route.name == "Play" || route.name == "Detail"
        ? (this.footerif = false)
        : (this.footerif = true);
    }
  },
  components: {},
  created() {
    //在页面加载时读取sessionStorage里的状态信息
    if (sessionStorage.getItem("store")) {
      this.$store.replaceState(
        Object.assign(
          {},
          this.$store.state,
          JSON.parse(sessionStorage.getItem("store"))
        )
      );
      this.isActive = this.$store.state.footerDate;
    }

    //在页面刷新时将vuex里的信息保存到sessionStorage里
    window.addEventListener("beforeunload", () => {
      sessionStorage.setItem("store", JSON.stringify(this.$store.state));
    });
  },
  mounted() {},
  methods: {}
};
</script>
<style lang='scss' scoped>
.homeaag {
  background: #000000;
}
.flec {
  height: 49px;

  display: flex;
  justify-content: center;
  align-items: center;
  a {
    display: block;
    width: 25%;
    height: inherit;
    color: #c9c3ae;
    text-align: center;
    // line-height: 49px;
    font-size: 12px;
    box-sizing: border-box;

    &.router-link-active {
      background: rgba($color: #292929, $alpha: 0);
      color: rgb(204, 204, 204);
    }
  }
  .van-icon {
    margin: 6px auto;
    display: block;
  }
}
.App-footer {
  width: 100%;
}
.homeg {
  background-color: rgba($color: #000000, $alpha: 0);
  // border-top: 1px saddlebrown solid;
  position: fixed;
  z-index: 1;
  bottom: 0;
}
</style>
